﻿using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HostsManager.Model
{
    sealed public class Configuration
    {
        private static int uniqueInternalIdCounter = 0;
        private static string GetNewInteralId() { return "_id" + (++uniqueInternalIdCounter); }

        internal string InternalId 
        { 
            get { return internalId; } 
        }
        private string internalId;

        public String Name
        {
            get { return name; }
            set { name = value; }
        }
        private String name;

        public bool Enabled
        {
            get { return enabled; }
            set { enabled = value; }
        }
        bool enabled;

        public String Content
        {
            get { return content; }
            set { content = value; }
        }
        String content = String.Empty;

        public Section ParentSection { get; set; }

        public Configuration(String Name, bool Enabled)
        {
            this.internalId = GetNewInteralId();
            this.name = Name;
            this.enabled = Enabled;
        }

        public void AddLine(String line)
        {
            if (line.StartsWith("#!"))
                content += line.Substring(2).Trim() + Environment.NewLine;
            else
                content += line + Environment.NewLine;

            //content = StringUtil.CompactBlankLines(content);
            content = StringUtil.RemoveBlankLines(content);
        }
    }
}